home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Examples / Example Libraries / StandardDialogs.vulib < prev    next >
Encoding:
Text File  |  1998-06-04  |  12.1 KB  |  338 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        StandardDialogs.vulib
  3. #
  4. #    Contains:    Sample tasks for working with standard Macintosh dialogs
  5. #
  6. #    Written by:    Sean Flynn, Jay Jessen, and P. Nagarajan
  7. #
  8. #    Copyright:    © 1990-1992 by Apple Computer, Inc., all rights reserved.
  9. #
  10. #    Change History (most recent first):
  11. #
  12. #         <5>     1/17/97    AR        Changed SetPaper task to handle page size popups
  13. #                  8/5/92    DGG        Added ColorPicker dialog handler.
  14. #         <4>     6/16/92    DGG        Added tasks to handle page setup dialog
  15. #                                    StandardDialogs.vulib now uses UtilityTasks.vulib
  16. #         <3>     8/26/91    Rick    Marked new tasks
  17. #         <2>     7/18/91    NAGA    update with changes made by David Gaxiola
  18. #                                    for running against System 7.0
  19. #        <1+>     7/18/91    NAGA    update with changes made by David Gaxiola for 
  20. #                                    running against System 7.0
  21. #                 4/25/89    SLF        Created.
  22. #
  23. #    To Do:
  24. #
  25.  
  26. Libraries "UtilityTasks.vulib";
  27.  
  28. (************************************************************************************
  29. * Task ColorPicker(hue, saturation, brightness,    red, green, blue)
  30. *    Handle standard Macintosh color picker dialog.  The values supplied correspond
  31. *    to the six fields available for typing.  If no change is desired, don't specify
  32. *    anything for a particular trait.
  33. ************************************************************************************)
  34. task ColorPicker(hue := undefined, saturation := undefined, brightness := undefined,
  35.                     red := undefined, green := undefined, blue := undefined)
  36. begin
  37.     FindObjectInWindow(122, 146);
  38.     doubleClick;
  39.     if hue
  40.         type k:{hue};
  41.     type k:{tabKey};
  42.     
  43.     if saturation
  44.         type k:{saturation};
  45.     type k:{tabKey};
  46.     
  47.     if brightness
  48.         type k:{brightness};
  49.     type k:{tabKey};
  50.     
  51.     if red
  52.         type k:{red};
  53.     type k:{tabKey};
  54.     
  55.     if green
  56.         type k:{green};
  57.     type k:{tabKey};
  58.     
  59.     if blue
  60.         type k:{blue};
  61.     type k:{tabKey};
  62.     
  63.     select [button t:"OK"];
  64. end;
  65.  
  66. (************************************************************************************
  67. * Task DoSaveAs( saveTitle := 'Untitled' ) begin
  68. *    Handle a simple case of work with the Standard file dialog.
  69. ************************************************************************************)
  70. task DoSaveAs( saveTitle := 'Untitled' ) 
  71. begin
  72.     wType := dialog;                            #see if dialog appeared
  73.     wButton1 := "Replace";                        #buttons to check for
  74.     wButton2 := "Yes";
  75.     select [menuItem t:/Save As≈/];                #menu selection
  76.     type k:{ saveTitle };                        #literal key strokes
  77.     select [button t:"Save"];                    #button press
  78.     # if the file exists, the "Do you want to replace" dialog will come up
  79.     # These if statements recognize that dialog and deal with it
  80.     if match[window s:wType] do begin
  81.         if match[button t:wButton1 e:false] do
  82.             select[button t:wButton1]; 
  83.         else if match[button t:wButton2 e:false] do
  84.             select[button t:wButton2];
  85.     end;
  86. end; # task DoSaveAs
  87.  
  88.  
  89. (************************************************************************************
  90. * Task SelectFromStandardFile(pathToFile,maximumNestingDepth)
  91. *    This task will select a file from the standard    file dialog.  It 
  92. *    navigates through the dialog by way of the keyboard.
  93. *    It takes two parameters, one is a list of file prefixes that will take
  94. *    the virtual user down to the file you want selected.  The list must 
  95. *    contain the strings that VU can type to reach the file.  They may be the
  96. *    complete folder names or enough of the folder name to distinguish them 
  97. *    from sibling folders.  The second is a number indicating the current 
  98. *    directory's maximum depth.  VU uses this number to get up to the top using
  99. *    command-up arrow.  By default, it is 15 so it isn't necessary to pass
  100. *    the second parameter.  The operation may be made faster, however, if you
  101. *    pass it a smaller number.  A sample call might look like this:
  102. *
  103. *        SelectFromStandardFile( { "HD","MPW","Interf","Cinclu","Palettes" },10 );
  104. *
  105. *    Because System 7.0 now has a "Desktop" in the FileSelector instead of a "Drive"
  106. *    button, be sure to include the desktop level when setting nesting depth and 
  107. *    in the path.
  108. *
  109. *    To only go back a specific number of folders as opposed to going all the way
  110. *    to the root level, set the maximumNestingDepth to the number of folders that 
  111. *    you wish to go back.
  112. *
  113. * NOTE: VU 2.0 Change in Functionality from VU 1.x!
  114. *        SelectFromStandardFile will now automatically press the return key at the 
  115. *        end to actually select the currently highlighted file.  To disable the
  116. *        automatic selection, set selectFile to false.
  117. ************************************************************************************)
  118. task SelectFromStandardFile(pathToFile,maximumNestingDepth := 15, selectFile := true) 
  119. begin
  120.     pressKey k: { commandKey };
  121.     for i := 1 to maximumNestingDepth 
  122.         type k:{ upArrowKey };
  123.     releaseKey k: { commandKey };
  124.     pathSize := card(pathToFile);
  125.     match [system v:?sysVer];
  126.     if sysVer ~= /7≈/ 
  127.         for i := 1 to pathSize - 1 
  128.             type k:{pathToFile[i],returnKey};
  129.     else
  130.         for i := 2 to pathSize - 1 
  131.             type k:{ pathToFile[i],returnKey };
  132.     type k: { pathToFile[pathSize] };
  133.     if selectFile
  134.         type k:{ returnKey };
  135. end;
  136.  
  137. (************************************************************************************
  138. * Task MakePageSetupActive()
  139. *    To be used by pageSetup() ... see below.
  140. *    Will check if a modal dialog is present and hopefully dispose of it.  Then it
  141. *    will open the Page Setup dialog.
  142. ************************************************************************************)
  143. task MakePageSetupActive()
  144. begin
  145.     match [window o:1 s:?winStyle];
  146.     if (winStyle = dialog)
  147.         select [button t:"OK" w:[window o:1]];
  148.     select [menuItem t:"Page Setup…" m:[menu t:"File"]];
  149. end;
  150.  
  151. (************************************************************************************
  152. * Task SetPaper(paperSize := "USLetter")
  153. *    To be used by pageSetup() ... see below.
  154. *    Will choose the appropriate size of paper in the Page Setup dialog.
  155. ************************************************************************************)
  156. task SetPaper(paperSize := "USLetter", printerType := "LaserWriter")
  157. begin
  158.     if    #a popup is used for "paper" or "page size", use a match for each device
  159.         #    Chooser allows
  160.         match [statictext t: "LaserWriter 300 Page Setup" w:1] or
  161.         match [statictext t: "LaserWriter 8 Page Setup" w:1] or
  162.         match [statictext t: "StyleWriter II Page Setup" w:1]
  163.         begin
  164.         match [window r: ?winCoord o:1];
  165.         paperCoord := locatestring ("Paper",winCoord,Chicago,12,,,,);
  166.         if isundefined (paperCoord)
  167.             paperCoord := locatestring ("Page Size",winCoord,Chicago,12,,,,);
  168.         if isundefined (paperCoord) 
  169.             println "neither page size nor paper was found";
  170.         else
  171.             begin
  172.             move a:{paperCoord[3] + 50, paperCoord[2] + 6};
  173.             pressmouse;
  174.             popupCoord := 0;
  175.             switch paperSize
  176.                 begin
  177.                 case "USLetter" :
  178.                     popupCoord := locatestring ("US Letter",winCoord,Chicago,12,,anyColor,anyColor,);
  179.                 case "USLegal" :
  180.                     popupCoord := locatestring ("US Legal",winCoord,Chicago,12,,anyColor,anyColor,);
  181.                 case "A4Letter" :
  182.                     popupCoord := locatestring ("A4",winCoord,Chicago,12,,anyColor,anyColor,);
  183.                 case "B5Letter" :
  184.                     popupCoord := locatestring ("B5",winCoord,Chicago,12,,anyColor,anyColor,);
  185.                 end;
  186.             if isundefined (popupCoord)
  187.                 println "### Unknown paper size for driver specified!  No action taken!";
  188.             else
  189.                 move a:    {(popupCoord[3] - popupCoord[1]) / 2 + popupCoord[1],
  190.                         (popupCoord[4] - popupCoord[2]) / 2 + popupCoord[2]};
  191.             releasemouse;
  192.             end;
  193.         end;
  194.     else
  195.         begin
  196.         #radiobuttons are used for paper size
  197.         #devices are:    LaserWriter Select 310
  198.         #                LaserWriter
  199.         #                AppleTalk ImageWriter
  200.         #                ImageWriter
  201.         #                Personal LaserWriter SC
  202.         if paperSize = "USLetter"
  203.             select [radioButton t:"US Letter"];
  204.         else if paperSize = "USLegal"
  205.             select [radioButton t:"US Legal"];
  206.         else if paperSize = "A4Letter"
  207.             select [radioButton t:"A4 Letter"];
  208.         else if ((paperSize = "B5Letter") and (not (printerType = "ImageWriter")))
  209.             select [radioButton t:"B5 Letter"];
  210.         else println "### Unknown paper size specified!  No action taken!";
  211.         end;
  212. end;
  213.  
  214. (************************************************************************************
  215. * Task SetScale(scale := 100, printerType := "LaserWriter")
  216. *    To be used by pageSetup() ... see below.
  217. *    Will set the scaling factor for the printer.
  218. ************************************************************************************)
  219. task SetScale(scale := 100, printerType := "LaserWriter")
  220. begin
  221.     if (printerType = "LaserWriter")
  222.     begin
  223.         FindObjectInWindow(133, 71);
  224.         doubleClick;
  225.         type k:{scale};
  226.     end;
  227.     else if ((printerType = "StyleWriter") and ((scale mod 20) = 0))
  228.     begin
  229.         match [window o:1 r:?winPosition];
  230.         scaleTextBox := {(winPosition[1]+272), (winPosition[2]+84), 
  231.                             (winPosition[3]-186), (winPosition[4]-32)};
  232.         FindObjectInWindow(318, 86);
  233.         match [staticText t:?currentScale r:scaleTextBox e:true];
  234.         while (currentScale <> "100")
  235.         begin
  236.             pressMouse;
  237.             releaseMouse;
  238.             match [staticText t:?currentScale r:scaleTextBox e:true];
  239.         end;
  240.         FindObjectInWindow(318, 98);
  241.         targetScale := numToStr(scale);
  242.         while (currentScale <> targetScale)
  243.         begin
  244.             pressMouse;
  245.             releaseMouse;
  246.             match [staticText t:?currentScale r:scaleTextBox e:true];
  247.         end;
  248.     end;
  249.     else if ((printerType = "ImageWriter") and ((scale mod 50) = 0))
  250.     begin
  251.         match [checkBox t:"50 % Reduction" s:?boxSetting];
  252.         if ((boxSetting[1] = 0) and (scale <> 100))
  253.             select [checkBox t:"50 % Reduction"];
  254.         else if ((boxSetting[1] = 1) and (scale <> 50))
  255.             select [checkBox t:"50 % Reduction"];
  256.     end;
  257.     else println "### Unsupported printer type, scale setting, or both!";
  258. end;
  259.  
  260. (************************************************************************************
  261. * Task SetOrientation(orientation := "portrait", printerType := "LaserWriter")
  262. *    To be used by pageSetup() ... see below.
  263. *    Will set the page orientation in the Page Setup dialog.
  264. *    buttonLocations is a list of the different printers supported.
  265. *        { LaserWriter, StyleWriter, ImageWriter }
  266. *    The list for each printer is another list of coordinates for the corresponding
  267. *    buttons of the form { portrait buton x, landscape button x, both button's y}
  268. *
  269. *    Failure for this task will return either 1 or 2 to signify a problem.
  270. *    
  271. ************************************************************************************)
  272. task SetOrientation(orientation := "portrait", printerType := "LaserWriter")
  273. begin
  274.     if ((orientation = "portrait") or (orientation = "landscape"))
  275.     begin
  276.         buttonLocations := { {81, 112, 134}, {120, 158, 100}, {29, 67, 118} };
  277.         match [window o:1 r:?winPosition];
  278.         if (printerType = "LaserWriter")
  279.             orientationPosition := buttonLocations[1];        
  280.         else if (printerType = "StyleWriter")
  281.             orientationPosition := buttonLocations[2];
  282.         else if (printerType = "ImageWriter")
  283.             orientationPosition := buttonLocations[3];
  284.         else 
  285.         begin
  286.             println "### Unsupported printer type ", printerType, "!";
  287.             return 2;
  288.         end;
  289.         if (orientation = "portrait")
  290.         begin
  291.             FindObjectInWindow(orientationPosition[1],orientationPosition[3]);
  292.             click;
  293.         end;
  294.         else
  295.         begin
  296.             FindObjectInWindow(orientationPosition[2], orientationPosition[3]);
  297.             click;
  298.         end;
  299.     end;
  300.     else
  301.     begin
  302.         println "### Unsupported orientation type ", orientation,"!";
  303.         return 1;
  304.     end;
  305. end;
  306.  
  307. (************************************************************************************
  308. * Task    PageSetup(printerType, paperSize, scale, orientation) 
  309. *     Handle Page Setup Dialog for multiple printers.  The following parameters are to 
  310. *    be given as strings, except the scale value which is an integer.
  311. *     Supported printer types:    LaserWriter
  312. *                                ImageWriter
  313. *                                StyleWriter
  314. *    Supported page sizes:        USLetter
  315. *                                USLegal
  316. *                                A4Letter
  317. *                                B5Letter
  318. *    Supporeted scale values:    any integer for LaserWriters
  319.                                 50 or 100 for ImageWriters
  320.                                 any multiple of 20 for StyleWriters
  321. *     Supported orientations:        portrait
  322. *                                landscape
  323. *
  324. *    This task will do _some_ checking for value validity.  Use of the scale value 
  325. *    must be with care as it will not check for an appropriate range, such as a value
  326. *    of zero or values greater than 100 on StyleWriters and ImageWriters.
  327. ************************************************************************************)
  328. task PageSetup(printerType := "LaserWriter", paperSize := "USLetter", scale := 100, 
  329.                 orientation := "portrait")
  330. begin
  331.     makePageSetupActive();
  332.     setPaper(paperSize, printerType);
  333.     setScale(scale, printerType);
  334.     setOrientation(orientation, printerType);
  335.     select [button t:"OK"];
  336. end;
  337.  
  338.